//
//  FRQDevicePairViewController.m
//  FRQBluetoothKit_Example
//
//  Created by admin on 2023/10/22.
//  Copyright © 2023 xuchunhai. All rights reserved.
//

#import "FRQDevicePairViewController.h"
#import "DevicePairs.h"
#import "UILabel+YBAttributeTextTapAction.h"
#import "FRQViewController.h"
#import "FRQLoginViewController.h"
@interface FRQDevicePairViewController ()
@property (nonatomic,strong) DevicePairs *devicePair;
@end

@implementation FRQDevicePairViewController

-(DevicePairs *)devicePair{
    if (nil==_devicePair) {
        _devicePair=skXibView(@"DevicePairs");
        [self.view addSubview:_devicePair];
        [_devicePair mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_topLayoutGuideTop);
            make.bottom.mas_equalTo(self.mas_bottomLayoutGuideBottom);
            make.right.left.mas_equalTo(0);
        }];
        @weakify(self)
        [[_devicePair.btnKefu rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self)
            FRQContactUsViewController *view=[[FRQContactUsViewController alloc] init];
            [self.navigationController pushViewController:view animated:YES];
        }];
        [[_devicePair.btnPairDeice rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self)
            FRQViewController *view=[[FRQViewController alloc] init];
            view.typeShow=0;
            [self.navigationController pushViewController:view animated:YES];
        }];
        
        [_devicePair.labTip yb_addAttributeTapActionWithStrings:@[@"Log Out"] tapClicked:^(NSString *string, NSRange range, NSInteger index) {
            @strongify(self);
            [self clearAllUserDefaultsData2];
            UIViewController *view=[[FRQLoginViewController alloc] init];
            UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:view];
            [[[UIApplication sharedApplication] delegate] window].rootViewController=nav;
        }];
    }
    return _devicePair;
}
/// 方法二：清除持久域
-(void)clearAllUserDefaultsData2{
    
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    
    NSDictionary *dic = [userDefaults dictionaryRepresentation];
    
    for(id key in dic){
        [userDefaults removeObjectForKey:key];
    }
    [userDefaults synchronize];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self devicePair];
    // Do any additional setup after loading the view.

}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
